import { config } from "./config"

export function request(url : string, data ?: any, isLoading = false) {
	return new Promise<{ code : number, data : any, msg ?: string, pagination ?: object }>((resolve, reject) => {
		if (isLoading) {
			uni.showLoading()
		}
		uni.request({
			url: config.API_BASE_URL + url,
			data: data,
			method: "POST",
			header: {
				"Authorization": uni.getStorageSync('token') ? "Bearer " + uni.getStorageSync('token') : ""
			},
			success: (res : any) => {
				resolve(res.data)
				uni.hideLoading()
			},
			fail: (err : any) => {
				reject(err)
			}
		});
	})
}